<!DOCTYPE html>
<html class="x-admin-sm">
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body class="">

    <div id="app" class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
          <button class="layui-btn"  @click="reload" lay-submit="" lay-filter="sreach" ><i class="layui-icon" >刷新页面</i></button>
        </form>
      </div>
      <table class="layui-table" >
        <thead>
          <tr>
            <td lay-data="{type:'checkbox'}">ID</td>
            <td lay-data="{field:'id', width:80, sort: true}">员工名</td>
            <td lay-data="{field:'username', width:120, sort: true, edit: 'text'}">头像</td>
            <td lay-data="{field:'email', edit: 'text', minWidth: 150}">工资</td>
            <td lay-data="{field:'sex', width:80,templet: '#switchTpl'}">年龄</td>
            <td lay-data="{field:'sex', width:80,templet: '#switchTpl'}">操作</td>
          </tr>
        </thead>
          <tr v-for="(item,index) in emps" :key="item.id">
            <td lay-data="{type:'checkbox'}">{{item.id}}</td>
            <td lay-data="{field:'id', width:80, sort: true}">{{item.name}}</td>
            <td lay-data="{field:'username', width:120, sort: true, edit: 'text'}">
                <img :src="'/'+item.path"  style="height: 60px"/>
            </td>
            <td lay-data="{field:'email', edit: 'text', minWidth: 150}">{{item.salary}}</td>
            <td lay-data="{field:'sex', width:80,templet: '#switchTpl'}">{{item.age}}</td>
            <td ><a href="javascript:;" @click="delEmp(item.id)" style="color: orangered">删除</a>&nbsp;<a href="javascript:;" @click="update(item.id)" style="color: dodgerblue">修改</a>
            </td>
          </tr>
      </table>

    </div>
    <script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">新增员工</button>
      </div>
    </script>



  </body>

</html>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
  var app = new Vue({
    el: "#app",
    data:{
      emps:[],
      visible:false,
      id:'',
    },
    methods:{
      reload(){
        location.reload();
      },
      delEmp(id){
        if(window.confirm("确定要删除这条ID为"+id+"的员工信息吗？")){
          axios.get("http://localhost:8080/emp/deleteByid?id="+id).then(res=>{
            if(res.data.state){
              alert(res.data.msg+"，点击确定刷新页面")
              location.reload();
            }else{
              alert(res.data.msg);
            }
          })
        }
      },
      update(id){
        window.open ("./employee-update.html?id="+id, "newWindow", "height=400, width=700, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
      }
    },
    created(){
      var _this = this;
      axios.get("http://localhost:8080/emp/findAll").then(res=>{
        _this.emps = res.data
      })
    }
  })
</script>